package net.aaa.hotel.dao.impl;

import net.aaa.hotel.dao.HRoleDao;
import net.aaa.hotel.entity.HRole;
import net.aaa.hotel.util.BaseDB;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
@Repository
public class HRoleDaoImpl implements HRoleDao {
    @Override
    public List<Map> findAll() {
        String sql = "select * from h_role";
        return BaseDB.queryMap(sql);
    }

    @Override
    public int delRole(String gid) {
        String sql = "delete from h_role where id=?";
        return BaseDB.update(sql,gid);
    }



    @Override
    public int addRole(HRole ro) {
        if (ro.getId() == null) {
            String sql = "insert into h_role (name)values(?)";
            return BaseDB.update(sql,ro.getName());
        }else {
            String sql = "update  h_role set name=? where id=?";
            return BaseDB.update(sql,ro.getName(),ro.getId());
        }
    }
}
